<?php
/**
 * Created by PhpStorm.
 * User: pengxu
 * Date: 2017/6/1
 * Time: 17:39
 */

/**
 * 递归生成无限极分类数组
 * @param $data
 * @param int $parent_id
 * @param int $count
 * @return array
 */
function tree(&$data, $pid = 0, $count = 1)
{
    static $treeList = [];

    foreach ($data as $key => $value) {
        if ($value['pid'] == $pid) {
            $value['count'] = $count;
            $treeList [] = $value;
            unset($data[$key]);
            tree($data, $value['id'], $count + 1);
        }
    }
    return $treeList;
}
/*
//拿到当前路由的控制器和方法
function getCurrentRoute()
{
    if (!function_exists('getCurrentAction')) {
        $action = Route::current()->getActionName();
        list($class, $method) = explode('@', $action);
        //dump($class);dump($method);
        $class = substr(strrchr($class, '\\'), 1);
        return ['controller' => $class, 'method' => $method];
    }
}*/

if ( ! function_exists('captcha_check')) {
    /**
     * @param $value
     * @return bool
     */
    function captcha_check($value)
    {
        return app('captcha')->check($value);
    }
}

if(!function_exists('ip')){
    function ip(){
        return \Illuminate\Support\Facades\Request::ip();
    }
}

